/*
 * Part of the ACID Project
 * Developed in 2011 by Morgan Taschuk
 */
package acid.plugin;

import acid.plugin.gui.AcidControlPanel;
import cytoscape.Cytoscape;
import cytoscape.plugin.CytoscapePlugin;
import cytoscape.util.CytoscapeAction;
import cytoscape.view.cytopanels.CytoPanelImp;
import java.awt.event.ActionEvent;
import javax.swing.SwingConstants;

/**
 *
 * @author morgan
 */
public class AcidPlugin extends CytoscapePlugin
{

    public AcidPlugin()
    {
        // (1) Create an Action
        AcidMenuPlugin menuAction = new AcidMenuPlugin(this);
        // (2) Add the action to Cytoscape menu
        Cytoscape.getDesktop().getCyMenus().addCytoscapeAction((CytoscapeAction) menuAction);

    }

    public class AcidMenuPlugin extends CytoscapeAction
    {

        public AcidMenuPlugin(AcidPlugin myPlugin)
        {
            // Add the menu item under menu "Plugins"
            super("ACID");
            setPreferredMenu("Plugins");

        }

        @Override
        public void actionPerformed(ActionEvent e)
        {
            //First, get a handler to the cytoPanel west, which is the control panel
            CytoPanelImp ctrlPanel = (CytoPanelImp) Cytoscape.getDesktop().getCytoPanel(SwingConstants.WEST);

            //Create a JPanel object (a class extends JPanel, say, MyPanel)
            AcidControlPanel myPanel = new AcidControlPanel();

//Add it to the control panel.
            ctrlPanel.add("ACID", myPanel);
            ctrlPanel.setSelectedIndex(ctrlPanel.getCytoPanelComponentCount() - 1);

        }
    }
}
